//封装功能函数，发起请求

import config from "./config"

export default (url, data={}, method='GET') => {
    return new Promise((resolve, reject) => {
    wx.request({
        url: config.host + url,
        data: data,
        method: method,
        header: {
            cookie: wx.getStorageSync('user_login') ? wx.getStorageSync('user_login').find( item => item.indexOf('MUSIC_U') !== -1) : ""
            // "Cookie": "123"
        },
        success: (res) => {
            // return callback(msg, err)
            //存储用户登录cookie到本地
            if(data.isLogin){
                wx.setStorage({
                    key: 'user_login',
                    data: res.cookies
                })
            }
            resolve(res.data)
        },
        fail: (err) => {
            // return callback(msg, err)
             reject(err)
        },
    })
})
}